import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:qunaimedical/components/custom_avatar.dart';
import 'package:qunaimedical/models/consultation_record.dart';
import 'package:qunaimedical/pages/record_detail.dart';
import 'package:qunaimedical/pages/record_receiver_list.dart';
import 'package:qunaimedical/pages/web_page.dart';

/// 我的会诊记录条目
class ItemRecord extends StatelessWidget {
  final ConsultationRecord item;
  final VoidCallback onDelete;

  const ItemRecord(this.item, {Key key, this.onDelete}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    String status;
    switch (item.status) {
      case '0':
        status = '未开始';
        break;
      case '1':
        status = '已开始';
        break;
      case '2':
        status = '已结束';
        break;
      default:
        status = '未开始';
    }
    return Slidable(
      actionPane: SlidableDrawerActionPane(),
      actionExtentRatio: 0.2,
      secondaryActions: <Widget>[
        IconSlideAction(
          caption: '删除',
          color: Colors.red,
          icon: Icons.delete_forever,
          onTap: onDelete,
        ),
      ],
      child: Container(
        color: Colors.white,
        child: Stack(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        CustomAvatar(
                          avatarUrl: item.avatar,
                          size: 70,
                          margin: EdgeInsets.all(16),
                        ),
                        Container(
                          padding:
                              EdgeInsets.symmetric(horizontal: 5, vertical: 2),
                          decoration: BoxDecoration(
                              color: Theme.of(context).primaryColor,
                              borderRadius:
                                  BorderRadius.all(Radius.circular(15))),
                          child: Text(
                            '预约会诊',
                            style: TextStyle(fontSize: 14, color: Colors.white),
                          ),
                        ),
                      ],
                    ),
                    Expanded(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: [
                          SizedBox(height: 16),
                          Row(
                            children: [
                              Container(
                                width: 80,
                                child: Text(
                                  '${item.fullname ?? ''}',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                    fontSize: 18,
                                    fontWeight: FontWeight.bold,
                                  ),
                                ),
                              ),
                              Text(
                                  '${item.sectionTypeNameDoctor} ${item.professionalName}'),
                              SizedBox(width: 10),
                            ],
                          ),
                          SizedBox(height: 5),
                          Padding(
                            padding: const EdgeInsets.only(bottom: 5.0),
                            child: Text('医学领域：${item.skilled}'),
                          ),
                          Divider(endIndent: 10),
                          Padding(
                            padding: const EdgeInsets.symmetric(vertical: 8),
                            child: Text('会诊类型：${item.consultationTypeName}'),
                          ),
                          Text(
                            '预约时间：${item.freeTime} ${item.morningAfternoon}',
                          ),
                          Padding(
                            padding: const EdgeInsets.symmetric(vertical: 8),
                            child: Text('主题：${item.title}'),
                          ),
                          Container(
                            child: Text('主诉：${item.content}'),
                            margin: EdgeInsets.only(bottom: 16),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Divider(),
                Container(
                  height: 50,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      InkWell(
                        onTap: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (c) =>
                                  RecordReceiverListPage(recordId: item.id),
                            ),
                          );
                        },
                        child: Row(
                          children: [
                            Image.asset('assets/images/ic_receiver.png',
                                width: 24),
                            Container(
                              child: Text('接受人'),
                              margin: EdgeInsets.only(left: 5),
                            ),
                          ],
                        ),
                      ),
                      InkWell(
                        child: Row(
                          children: [
                            Image.asset('assets/images/ic_desc.png', width: 24),
                            Container(
                              child: Text('详情'),
                              margin: EdgeInsets.only(left: 5),
                            ),
                          ],
                        ),
                        onTap: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (c) => RecordDetailPage(id: item.id),
                            ),
                          );
                        },
                      ),
                      InkWell(
                        onTap: () {
                          Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) =>
                                      WebPage(url: item.meetingUrl)));
                        },
                        child: Row(
                          children: [
                            Image.asset('assets/images/ic_zhibo.png',
                                width: 24),
                            Container(
                              child: Text('直播间'),
                              margin: EdgeInsets.only(left: 5),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
            Positioned(
              child: Text(
                status,
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  color: Colors.red,
                ),
              ),
              right: 10,
              top: 10,
            ),
          ],
        ),
      ),
    );
  }
}
